package edu.dgut.bbssystem.util;

import edu.dgut.bbssystem.pojo.Comment;
import edu.dgut.bbssystem.pojo.Follow;
import edu.dgut.bbssystem.pojo.Message;
import edu.dgut.bbssystem.pojo.User;

import javax.servlet.http.HttpSession;
import java.util.Date;

public class BbsUtils {
    public static User getUserInSession(HttpSession session){
        User user =(User) session.getAttribute("user");
        return user;
    }
    public static Message getGeneralMessage(int senderId){
        Message message = new Message();
        message.setAlreadyIgnore(0);
        message.setAlreadyRead(0);
        message.setMessageTime(new Date());
        message.setSenderId(senderId);
        return  message;
    }
    public static Message getInitialMessage(int senderId, Comment comment){
        Message message = getGeneralMessage(senderId);
        message.setFloor(comment.getFloor());
        message.setPostId(comment.getPostId());
        return  message;
    }
    public static Message getInitialMessage(int senderId, Follow follow){
        Message message = getGeneralMessage(senderId);
        message.setFollowId(follow.getFollowmessageId());
        message.setMessageTypeId(1);
        return  message;
    }
}
